package com.itcat.controller;

import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.param.DeliveryParam;
import com.itcat.mysql.param.MoneyInfoParam;
import com.itcat.mysql.param.OmsOrderParam;
import com.itcat.mysql.param.ReceiverInfoParam;
import com.itcat.mysql.pojo.OmsOrder;
import com.itcat.mysql.vo.OmsOrderVo;
import com.itcat.service.OmsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/order")
public class OmsOrderController {

    @Autowired
    private OmsOrderService omsOrderService;


    /**
     * 分页查询订单详情
     *
     * @return
     */
    @GetMapping("list")
    public CommonResult OrderList(OmsOrderParam omsOrderParam) {
        CommonPage<OmsOrder> pageResult = omsOrderService.OrderList(omsOrderParam);
        return CommonResult.success(pageResult);
    }

    /**
     * 批量删除订单
     *
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(Integer[] ids) {
        omsOrderService.delete(ids);
        return CommonResult.success(null);
    }

    /**
     * 批量关闭订单
     *
     * @return
     */
    @PostMapping("/update/close")
    public CommonResult close(Integer[] ids, String note) {
        omsOrderService.close(ids, note);
        return CommonResult.success(null);
    }


    /**
     * 批量发货
     *
     * @return
     */
    @PostMapping("/update/delivery")
    public CommonResult delivery(@RequestBody List<DeliveryParam> list) {
        omsOrderService.delivery(list);
        return CommonResult.success(null);
    }


    /**
     * 查询订单详情
     *
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult orderDetail(@PathVariable Integer id) {
        OmsOrderVo vo = omsOrderService.orderDetail(id);
        return CommonResult.success(vo);
    }

    /**
     * 订单备注
     *
     * @return
     */
    @PostMapping("/update/note")
    public CommonResult note(Integer id, String note, Integer status) {
        omsOrderService.note(id, note, status);
        return CommonResult.success(null);
    }

    /**
     * 修改收货人信息
     *
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public CommonResult receiverInfo(@RequestBody ReceiverInfoParam receiverInfoParam) {
        omsOrderService.receiverInfo(receiverInfoParam);
        return CommonResult.success(null);
    }

    /**
     * 修改订单费用信息
     *
     * @return
     */
    @PostMapping("/update/moneyInfo")
    public CommonResult moneyInfo(@RequestBody MoneyInfoParam moneyInfoParam) {
        omsOrderService.moneyInfo(moneyInfoParam);
        return CommonResult.success(null);
    }
}
